﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using FhlowSharp.Gui.Properties;

namespace FhlowSharp.Gui
{
    public partial class ApplicationView : Form
    {
        //private FhlowApplications _applications;

        public ApplicationView()//(FhlowApplications apps)
        {
            InitializeComponent();
            //if(Settings.Default.ApplicationConfigFilePath != null && Settings.Default.ApplicationConfigFilePath.ApplicationList != null )
            //    AppList.Items.AddRange(Settings.Default.ApplicationConfigFilePath.ApplicationList.ToArray());
            //_appType.Items.Add("Simulator Application");
            //_appType.Items.Add("Synthesis Application");
            //_applications = apps;
            _appType.SelectedIndex = 0;
            UpdateAppList();
        }

        private void UpdateAppList()
        {
            AppList.Items.Clear();
            //AppList.Items.AddRange(_applications.SimulatorApplications.ToArray());
        }
        private void ClearForm()
        {
            _name.Text = string.Empty;
            _header.Text = string.Empty;
        }
        //private void AddSimApplication(SimulatorApplication appl)
        //{
        //    if (_applications.SimulatorApplications.Exists(app => app.ApplName == appl.ApplName))
        //        throw new Exception("A application with the same name allready exists");
        //    _applications.SimulatorApplications.Add(appl);
        //}
        //private void AddSynApplication(SynthesisApplication appl)
        //{
        //    if (_applications.SynthesisApplications.Exists(app => app.ApplName == appl.ApplName))
        //        throw new Exception("A application with the same name allready exists");
        //    _applications.SynthesisApplications.Add(appl);
        //}
        private void AddButtonClick(object sender, EventArgs e)
        {
        //    try
        //    {
        //        if ((string)_appType.SelectedItem == "Simulator Application")
        //        {
        //            var simAppl = new SimulatorApplication();
        //            simAppl.ScriptHeader = _header.Text;
        //            simAppl.ApplName = _name.Text;
        //            simAppl.CheckData();
        //            AddSimApplication(simAppl);
        //            Settings.Default.Save();
        //        }
        //        UpdateAppList();
        //        ClearForm();
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }

        }

        private void RefreshButtonClick(object sender, EventArgs e)
        {
            UpdateAppList();
        }
    }
}